#version 330 core

in vec2 TexCoords;

uniform float Time;
uniform vec2 MousePos;
uniform vec2 Size;
uniform sampler2D image;
uniform sampler2D imageNoise;
uniform sampler2D imageWater;
uniform float DrawBg;

out vec4 FragColor;

void main()
{
	if(DrawBg > 0.0)
	{
		vec4 color = texture2D(image, TexCoords * 2.0);
		
		if(TexCoords.x > 0.5){
			color.a = 0.0;
		}
		if(TexCoords.y < 0.5){
			color.a = 0.0;
		}
		FragColor = color;
	}
	else{
		
		float scale_UV = 0.05f;
		vec4 noise_color = texture2D(imageNoise, TexCoords + Time * 0.1);

		vec2 UV = vec2(TexCoords.x + noise_color.r * scale_UV, 1.0 - TexCoords.y) * 2.0;
		vec4 color = texture2D(image, UV);
		vec4 water_color = texture2D(imageWater, UV);

		if(UV.x > 1.0){
			water_color.a = color.a = 0.0;
		}
		if(UV.y < 1.0){
			water_color.a = color.a = 0.0;
		}
		
		color = mix(water_color, color, color.a);
		
		FragColor = color;
	}
	
}
